Skip to main content
Version: 25.06

Testing Ingress Controller

To test the Ingress controller within a Kubernetes cluster, you must first set up a test environment, configure the ingress resource with the necessary rules, and verify that the connection works.

  1. Create a test deployment within a test environment.

    kubectl create deployment hello-world --image=hashicorp/http-echo --port=5678 -- --text="hello world"

    This command creates a deployment called “hello-world” using the “hashicorp/http-echo” image. The container will listen on port “5678” and respond with the text “hello-world”.

  2. Next, expose the deployment as a service.

    kubectl expose deployment hello-world --port=80 --target-port=5678

    This command creates a service called “hello-world” that maps the external port “80” to the container’s port “5678” in your Kubernetes cluster. This setup allows external traffic to reach your deployment through the designated port.

  3. Create and apply the Ingress resource using the following routing rules.

    kubectl apply -f - <<EOF
    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
    name: hello-world
    annotations:
    # For AWS:
    # kubernetes.io/ingress.class: alb
    # For GCP:
    # kubernetes.io/ingress.class: gce
    spec:
    # For Azure:
    # className: webapprouting.kubernetes.azure.com
    rules:
    - http:
    paths:
    - path: /
    pathType: Prefix
    backend:
    service:
    name: hello-world
    port:
    number: 80
    EOF

    This command creates an Ingress resource called “hello-world” and defines rules to forward all the HTTP traffic to the “hello-world” service on port “80”. Uncomment the rule specific to your cloud provider (AWS, Azure, or GCP).

  4. To verify that the connection works,

    1. Get the Ingress IP address.

      IP=$(kubectl get ingress hello-world -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
    2. Update /etc/hosts if DNS is not configured (replace 'example.com' with your domain).

      echo "$IP hello-world.example.com" | sudo tee -a /etc/hosts
    3. Test the Ingress.

      curl http://hello-world.example.com